<?php

namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request; //命名空间的三元素：常量，方法和类
use DB;
use App\Http\Model\Dingdan;

class DingdanController extends Controller
{
    // 显示订单信息
    public function LookDingdan(){
        $result = Dingdan::paginate(6);
        return view('admin/user/dingdan',compact('result'));
    }
 
    // 显示订单修改内容
    public function Xgdingdan($id){
        $result =  Dingdan::where('orderid',$id)->first();
        $bookname = explode("@", $result->spc);
        $booknumber = explode("@", $result->slc);
        return view('admin/user/xgdingdan',compact('result','bookname','booknumber'));
    }

    // 修改订单
    public function DingdanUp(Request $request){
    $data = $request->all();
    $data['zt'] = $request->input('zt');
    $id = $request->get('orderid');;
    // 删除token等多余的列
    unset($data['_token']);
    // unset($data['ok']);
  
    $result = Dingdan::where('orderid',$id)->update($data);

      if($result>0){
          return redirect('admin/dingdan');
      }
      else
      {
          return back();
      }
   
    }

    // 删除订单内容
      public function Deldingdan($id){
        Dingdan::where('orderid',$id)->delete();
        return ['status'=>0,'msg'=>'删除成功'];
        // $result =  Dingdan::where('orderid',$id)->delete();
        // if($result > 0){
        //     return back();
        // }
    }

     // 复选框删除
     public function Delalldd(){
        foreach ($_POST['checked'] as $key => $id) {
          $result =  Dingdan::where('orderid',$id)->delete();
        }
        if($result>0){
            return redirect('admin/dingdan');
        }
        else
        {
            return back();
        }
       
    }

   
}